<template>
	<up-form @submit.prevent="onSubmit">
		<up-form-item borderBottom labelWidth='120rpx' style="padding-left: 30rpx;">
			<up-textarea v-model="content" placeholder="请输入贴子内容，内容大于10" count :maxlength="500"></up-textarea>
		</up-form-item>

		<view style="margin: 16px;">
			<up-button type="primary" @click="onSubmit"  shape='circle'>
				提交
			</up-button>
		</view>
	</up-form>
</template>

<script setup lang="ts">
	import { ref } from "vue";
	import myAxios from '@/plugins/myAxios';
	const content = ref('');

	// 提交表单
	const onSubmit = async () => {
		try {
			const [error, res] = await myAxios.post("/post/add", {
				content: content.value,
			})
			if (!error && res?.data?.code === 0) {
				// 显示成功提示
				uni.showToast({
					title: '添加成功',
					icon: 'success',
					duration: 2000,
				});
				// 跳转页面
				// 返回到上一页
				uni.navigateBack({
					delta: 1, // 返回的层级，默认为1，即返回到上一级页面
				});
			} else {
				// 显示失败提示
				uni.showToast({
					title: `添加失败: ${res?.data?.description || '未知错误'}`,
					icon: 'none',
					duration: 2000,
				});
			}
		} catch (error) {
			// 捕获请求错误
			uni.showToast({
				title: '网络错误，请稍后重试',
				icon: 'none',
				duration: 2000,
			});
		}
	};

	// 其他示例变量
	const value = ref(1);
</script>


<style>
</style>